<?php

/*
  Project     : 48c6c450f1a4a0cc53d9585dc0fee742
  Created on  : Mar 16, 2013, 11:29:15 PM
  Author      : Truong Khuong - khuongxuantruong@gmail.com
  Description :
  Purpose of the stylesheet follows.
 */

class user_model extends backend_model {
    function __construct()
    {
        parent::__construct('auth_users','ause');
    }
    function get($_id){
        $query=$this->db
                ->where("ause_id",$_id)
                ->get("auth_users");
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            //baotri("$error_message");
            return null;
        }
        $rs = $query->result();
        if(isset($rs[0]))   {
            return $rs[0];
        }
        return null;
    }
    function gets(){
        $query=$this->db
                ->where('ause_delete',null)
                ->order_by('ause_position','DESC')
                ->order_by('ause_insert','DESC')
                ->get('auth_users');
        $error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return null;
        }
        $rs = $query->result();
        return $rs;
    }
    function insert($params){
        //$this->db->set('_insert', 'NOW()', FALSE);
        @$this->db->insert("auth_users", $params); 
		$error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        @$count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function update($ID,$params){
        $this->db->set('ause_update', 'NOW()', FALSE);
        $this->db->where('ause_id', $ID);
        @$this->db->update("auth_users", $params); 
		$error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        @$count = $this->db->affected_rows(); //should return the number of rows affected by the last query
        if($count==1) return true;
        return false;
    }
    function insert_onduplicate_update_aupr($aParamsi,$aUpdate){
        $this->db->on_duplicate_update('auth_user_privilege', $aUpdate, $aParamsi); 
        $count = $this->db->affected_rows();
		$error_number = $this->db->_error_number();
        $error_message = $this->db->_error_message();
        if($error_number!==0){
            $_SESSION['auth_db']['errors'][]=$error_message;
            return false;
        }
        if($count>0) return $count;
        return false;
    }
    function binding(){
        $position=isset($_SESSION["auth"]["user"])?$_SESSION["auth"]["user"]->ause_position:0;
        $this->datatables_config=array(
                    "table"=>"auth_users",
                    "where"=>"WHERE  `ause_position`<=$position",
                    "order_by"=>" ORDER BY `ause_insert` DESC ",
                    "columnmaps"=>array(
                            
                    )
        );
        return $this->_bindingdata();
    }
    
}

?>
